<template>
  <section>
    <section v-if="showInfo && companyAuth" @click="clickBottomHref" :class="[bottomCorpInfoBg, hasBottomFixedBtn && hasNotice ? 'c-pb160' : (((hasBottomFixedBtn && !isMicropage && !extraPaddingBottom ) || (isMicropage && hasBottomNav)) ? 'c-pb120': (hasBottomFixedBtn && !isMicropage && extraPaddingBottom ? extraPaddingBottom : ''))]" class="c-maxw640 c-w100 c-pv40 c-flex-column c-aligni-center c-fs22 c-fc-sgray">
      <div class="c-flex-row c-aligni-center">
        <img src="@/assets/cklogo.png" class="c-ww24 c-hh24" />
        <span class="c-ml10">{{ !companyAuth.instruction || showDefaultText ? '创客匠人技术支持' : companyAuth.instruction }}</span>
      </div>
      <span class="c-mt2">{{ linkText }}</span>
    </section>
    <section v-else-if="(!showInfo && (hasBottomFixedBtn && !isMicropage)) || (isMicropage && hasBottomNav) || extraPaddingBottom" :class="hasNotice ? 'c-pb120' : extraPaddingBottom ? extraPaddingBottom : 'c-pb80'">
    </section>
    <section v-if="customButtonPadding != 0" :style="'padding-bottom: ' + customButtonPadding + 'px'"></section>
  </section>
</template>
<script>
import { utilJs } from '@/utils/common.js';
export default {
  name: 'bottomCompanyInfo',
  components: {},
  props: {
    showInfo: {
      //是否显示底部信息
      type: Boolean,
      default: false
    },
    showDefaultText: {
      //是否显示默认文案 =》 即是否包年直播或分销课程
      type: Boolean,
      default: true
    },
    hasBottomFixedBtn: {
      //是否有底部悬浮按钮，需要腾出80px
      type: Boolean,
      default: true
    },
    isMicropage: {
      type: Boolean,
      default: false
    },
    extraPaddingBottom: {
      type: String,
      default: ''
    }
  },
  computed:{
    linkText:function() {
      if (!this.companyAuth) {
        return '';
      }
      let text = !this.companyAuth.netAddress || this.showDefaultText ? 'http://www.ckjr001.com' : this.companyAuth.netAddress;
      //包年直播或分销 && 关闭直播网址显示
      text = this.showDefaultText && this.companyAuth.liveModuleShowType == 1 ? '' : text;
      //其他模式 && 关闭网址显示
      text = !this.showDefaultText && this.companyAuth.otherModuleShowType == 1 ? '' : text;
      return text;
    },
    hasNotice: function() {
      return this.$store.state.oem_store.hasNoticeText
    }
  },
  watch: {
    $route(to, from) { // hasBottomNav这个是微页面判断间隔的标识，hasBottomNav在路由切换也需要计算，所以watch也进行赋值，默认mounted也赋值
      this.hasBottomNav = sessionStorage.getItem('microBottomFixed') ? JSON.parse(sessionStorage.getItem('microBottomFixed')) : false;
      setTimeout(() => {
      this.hasBottomNav = sessionStorage.getItem('microBottomFixed') ? JSON.parse(sessionStorage.getItem('microBottomFixed')) : false;
      }, 2000);
      this.bottomCorpInfoBg = to.meta && to.meta.bottomCorpInfoBg ? to.meta.bottomCorpInfoBg : ''
    }
  },
  data() {
    return {
      companyAuth: null,
      customButtonPadding: 0,
      hasBottomNav: false,
      bottomCorpInfoBg: ''
    };
  },
  mounted() {
    this.companyAuth = localStorage.getItem('companyAuth') && JSON.parse(localStorage.getItem("companyAuth")) || null;
    this.$nextTick(() => {
      this.hasBottomNav = sessionStorage.getItem('microBottomFixed') ? JSON.parse(sessionStorage.getItem('microBottomFixed')) : false;
      if (!document.getElementById('customButton')) return
      let domH = document.getElementById('customButton').clientHeight;
      this.customButtonPadding = (domH - 40) > 0 ? domH - 40 : 0;
    })
    //防止刚进入页面没获取到，3s后重新去获取一次
    setTimeout(() => {
      this.hasBottomNav = sessionStorage.getItem('microBottomFixed') ? JSON.parse(sessionStorage.getItem('microBottomFixed')) : false;
      this.companyAuth = localStorage.getItem('companyAuth') && JSON.parse(localStorage.getItem("companyAuth")) || null;
      if (!document.getElementById('customButton')) return
      let domH = document.getElementById('customButton').clientHeight;
      this.customButtonPadding = (domH - 40) > 0 ? domH - 40 : 0;
    }, 3000);
    this.bottomCorpInfoBg = this.$route.meta && this.$route.meta.bottomCorpInfoBg ? this.$route.meta.bottomCorpInfoBg : ''
  },
  methods: {
    clickBottomHref() {
      if (utilJs.isIOSAppALL()) {
        return;
      }
      let companyId = localStorage.getItem('companyId') || 'lj7l';
      //林煜国学 根据开关，点击底部不跳转
      let noGoArr = ['g976v2'];
      //中联云课 明師書院  索学智库研究院 艺叔学堂 伍方境 商家点击所有链接都不跳转
      let allDisalbeClickArr = ['jz5zdz', 'm8w62w', 'a983x6', 'zkyjmv', 'a99w86'];
      if (allDisalbeClickArr.includes(companyId)) {
        return;
      }
      if (!this.showDefaultText && this.companyAuth.otherModuleShowType == 1 && noGoArr.includes(companyId)) {
        return;
      }
      if (this.showDefaultText || !this.companyAuth.netAddress) {
        // window.location.href = 'http://www.ckjr001.com?ch=jishuzhichi';
        // 20220512改为不跳转官网，跳转到设置的提交意向客户名单的页面
        // this.$routerGo(this, "push", { path: "/homePage/about/companyInfoSubmit" });
        // 20241012 品牌部让改为跳转官网的表单页面
        window.location.href = 'http://m.ckjr001.com/form.html?ch=jishuzhichi';
        return;
      }
      if (this.companyAuth.netAddress && this.companyAuth.netAddress.includes('www.ckjr001.com')) {
        // window.location.href = 'http://www.ckjr001.com?ch=jishuzhichi';
        // this.$routerGo(this, "push", { path: "/homePage/about/companyInfoSubmit" });
        // 20241012 品牌部让改为跳转官网的表单页面
        window.location.href = 'http://m.ckjr001.com/form.html?ch=jishuzhichi';
        return;
      }
      if (this.companyAuth.netAddress.includes('http') || this.companyAuth.netAddress.includes('https')) {
        window.location.href = this.companyAuth.netAddress;
      } else {
        window.location.href = 'http://' + this.companyAuth.netAddress;
      }
    }
  }
};
</script>
